# -*_ codeing=utf-8 -*-
# @Time: 2025/10/27 17:26
# @Author: foxhuty
# @File: update_data.py
# @Software: PyCharm
# @Based on python 3.10
from sqlalchemy import update
from sqlalchemy.orm import sessionmaker
from sqlalchemy_notes.db_main import engine
from sqlalchemy_notes.student_manager.models import Student,Department

with sessionmaker(bind=engine).begin() as session:
#     emp = session.get(Student, 2)
#     emp.name = '早田希娜'
#     print(emp)
# #第二种修改更优化
#     stmt=update(Student).where(Student.id ==3).values(name="拜登",salary=1000)
#     session.execute(stmt)
#批量修改
    # session.execute(update(Student),[
    #     {'id':1,'bonus':800},
    #     {'id':2,'bonus':1000},
    # ])
    # 级联修改
    stu=session.get(Student,7)
    dept=session.get(Department,1)
    stu.dept_id=dept.id


